package com.chenyaowei.web.controller.member;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.chenyaowei.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenyaowei.common.annotation.Log;
import com.chenyaowei.common.core.controller.BaseController;
import com.chenyaowei.common.core.domain.AjaxResult;
import com.chenyaowei.common.enums.BusinessType;
import com.chenyaowei.member.domain.CywGrowthChangeHistory;
import com.chenyaowei.member.service.ICywGrowthChangeHistoryService;
import com.chenyaowei.common.utils.poi.ExcelUtil;
import com.chenyaowei.common.core.page.TableDataInfo;

/**
 * 成长值变化历史记录Controller
 *
 * @author 陈耀威
 * @date 2023-11-28
 */
@RestController
@RequestMapping("/member/growthChangeHistory")
public class CywGrowthChangeHistoryController extends BaseController
{
    @Autowired
    private ICywGrowthChangeHistoryService cywGrowthChangeHistoryService;

    @Anonymous
    @GetMapping("/list/currentUser")
    public TableDataInfo listByMemberId(CywGrowthChangeHistory cywGrowthChangeHistory)
    {
        startPage();
        cywGrowthChangeHistory.setMemberId(getUserId());
        List<CywGrowthChangeHistory> list = cywGrowthChangeHistoryService.selectCywGrowthChangeHistoryList(cywGrowthChangeHistory);
        return getDataTable(list);
    }

    /**
     * 查询成长值变化历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('member:growthChangeHistory:list')")
    @GetMapping("/list")
    public TableDataInfo list(CywGrowthChangeHistory cywGrowthChangeHistory)
    {
        startPage();
        List<CywGrowthChangeHistory> list = cywGrowthChangeHistoryService.selectCywGrowthChangeHistoryList(cywGrowthChangeHistory);
        return getDataTable(list);
    }

    /**
     * 导出成长值变化历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('member:growthChangeHistory:export')")
    @Log(title = "成长值变化历史记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CywGrowthChangeHistory cywGrowthChangeHistory)
    {
        List<CywGrowthChangeHistory> list = cywGrowthChangeHistoryService.selectCywGrowthChangeHistoryList(cywGrowthChangeHistory);
        ExcelUtil<CywGrowthChangeHistory> util = new ExcelUtil<CywGrowthChangeHistory>(CywGrowthChangeHistory.class);
        util.exportExcel(response, list, "成长值变化历史记录数据");
    }

    /**
     * 获取成长值变化历史记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('member:growthChangeHistory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cywGrowthChangeHistoryService.selectCywGrowthChangeHistoryById(id));
    }

    /**
     * 新增成长值变化历史记录
     */
    @PreAuthorize("@ss.hasPermi('member:growthChangeHistory:add')")
    @Log(title = "成长值变化历史记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CywGrowthChangeHistory cywGrowthChangeHistory)
    {
        return toAjax(cywGrowthChangeHistoryService.insertCywGrowthChangeHistory(cywGrowthChangeHistory));
    }

    /**
     * 修改成长值变化历史记录
     */
    @PreAuthorize("@ss.hasPermi('member:growthChangeHistory:edit')")
    @Log(title = "成长值变化历史记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CywGrowthChangeHistory cywGrowthChangeHistory)
    {
        return toAjax(cywGrowthChangeHistoryService.updateCywGrowthChangeHistory(cywGrowthChangeHistory));
    }

    /**
     * 删除成长值变化历史记录
     */
    @PreAuthorize("@ss.hasPermi('member:growthChangeHistory:remove')")
    @Log(title = "成长值变化历史记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cywGrowthChangeHistoryService.deleteCywGrowthChangeHistoryByIds(ids));
    }
}
